# typed: true
# frozen_string_literal: true

require File.expand_path("../Abstract/abstract-php-extension", __dir__)

# Class for Protobuf Extension
class ProtobufAT74 < AbstractPhpExtension
  init
  desc "Protobuf PHP extension"
  homepage "https://github.com/protocolbuffers/protobuf"
  url "https://pecl.php.net/get/protobuf-3.24.4.tgz"
  sha256 "46a1cfa2e7680e8ad08d0e0aee6d51588502fb7112b6f2e1388f0f4c6ebf1385"
  head "https://github.com/protocolbuffers/protobuf.git", branch: "main"
  license "BSD-3-Clause"

  bottle do
    root_url "https://ghcr.io/v2/shivammathur/extensions"
    sha256 cellar: :any_skip_relocation, arm64_sequoia:  "e5ad87f2b262d936c97b0c9b9f798734bf32d888efc11e0908cb5be6e87ddd9b"
    sha256 cellar: :any_skip_relocation, arm64_sonoma:   "8e35424b4311a19cce3bd616e4757625627c6eecf3d804b354cda9e6cc20f98e"
    sha256 cellar: :any_skip_relocation, arm64_ventura:  "b4e018df3faf93ab56e303b2ce2b5243aada1a3484be20177fb763a48fde57f8"
    sha256 cellar: :any_skip_relocation, arm64_monterey: "da2b0f1e4ca9aecb686ac2acf54492f0470597c83ce65450f56d7c75a5f29595"
    sha256 cellar: :any_skip_relocation, sonoma:         "1c300b0b022cb6ffcedde5d19eb13197e0b1da9aa2211e9a9e324f5952d414e7"
    sha256 cellar: :any_skip_relocation, ventura:        "dd2bfbb6cfc9f3b427b6432b7e7ce05945444226996981bf1e11aade6dfa1c78"
    sha256 cellar: :any_skip_relocation, monterey:       "7515686432f3f78640c34fe7d93cbad7ed598926314ccdb2299be03b55384b72"
    sha256 cellar: :any_skip_relocation, arm64_linux:    "26835ed8819afd059702d5d800969e95d55effe3c2d1260479bfbf668153e8a3"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "e3174e61409f590a9ec6a99e18ba7f6cc5d28590cc688e67017551ffa1cf622b"
  end

  def install
    Dir.chdir "protobuf-#{version}"
    safe_phpize
    system "./configure", "--enable-protobuf"
    system "make"
    prefix.install "modules/#{extension}.so"
    write_config_file
  end

  def caveats
    <<~EOS
      Copyright 2008 Google Inc.  All rights reserved.

      Redistribution and use in source and binary forms, with or without
      modification, are permitted provided that the following conditions are
      met:

          * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
          * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following disclaimer
      in the documentation and/or other materials provided with the
      distribution.
          * Neither the name of Google Inc. nor the names of its
      contributors may be used to endorse or promote products derived from
      this software without specific prior written permission.

      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

      Code generated by the Protocol Buffer compiler is owned by the owner
      of the input file used when generating it.  This code is not
      standalone and requires a support library to be linked with it.  This
      support library is itself covered by the above license.

      To finish installing #{extension} for PHP #{php_version}:
        * #{config_filepath} was created,"
          do not forget to remove it upon extension removal."
        * Validate installation by running php -m
    EOS
  end
end
